globalConfig = {
	web:'http://127.0.0.1:4000',
	// web:'http://47.52.29.233:4000',
	app: ''
};


(function(document) {

	globalConfig.app = angular.module('app', ['ui.router','oc.lazyLoad']);

	var routerList = [
		'app/home/home.js',
		'app/detail/detail.js',
		'app/me/me.js',
		'app/gold/gold.js',
	];
	
	var str = '';
	routerList.forEach(function(router) {
		str += '<script src="' + router + '"></script>';
	});
	document.write(str);

}(document));


angular.module('app').config(['$urlRouterProvider', function($urlRouterProvider) {
	$urlRouterProvider.when('', '/home');
}]);

angular.module('app').controller('rootCtrl',['$rootScope','http',function($rootScope,http){
	$rootScope.header = http.cacheUtil.get("header");
	$rootScope.user = {username:'', password:''}
	$rootScope.login = function(){
		var reqUrl = globalConfig.web + "/user/signin";
        http.signin(reqUrl, $rootScope.user, function(data, status){
			if(status==200){
				http.cacheUtil.put("Authorization", data.token);
				http.cacheUtil.put("header", true);
				$rootScope.header = true;
			}else{
        		alert("账号或密码错误")
			}
		});
	}

	$rootScope.logout = function(){
		http.get(globalConfig.web+'/user/logout', function(data, status){
			http.cacheUtil.remove("Authorization")
			http.cacheUtil.remove("header")
            $rootScope.header = false;
        })
	}
   
}]).factory('stateV', function() {
	var savedData = {}
 	function set(data) {
   		savedData = data;
 	}
	function get() {
  		return savedData;
 	}
 	return {
  		set: set,
  		get: get
 	}
});

(function(document) {
	var libList = [
		'app/base/other/filter.js',
		'app/base/other/httpUtil.js',
	];
	var str = '';
	libList.forEach(function(lib) {
		str += '<script src="' + lib + '"></script>';
	});
	document.write(str);
}(document));


//延迟加载
var lazyloadlib = [
	'app/base/directive/datepicker.js',
];



